package net.chrone.quickpayapi.util;

import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;

public class RegexUtil {

	//手机号码验证
	public static boolean validMobile(String mobile){
		Pattern pattern = Pattern.compile("1[3|5|7|8|][0-9]{9}");
		return pattern.matcher(mobile).matches();
	}
	
	//卡号格式验证
	public static boolean validCard(String cardNo) {
		Pattern pattern = Pattern.compile("\\d{9,22}");
		return pattern.matcher(cardNo).matches();
	}
	
	//验证身份证
	public static boolean validIDCard(String certNo) {
		if(StringUtils.isEmpty(certNo)){
			return false;
		}
		int length = certNo.trim().length();
		if(15==length){
			Pattern pattern = Pattern.compile("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$");
			return pattern.matcher(certNo).matches();
		}else if(18==length){
			Pattern pattern = Pattern.compile("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}(\\d|x|X)$");
			return pattern.matcher(certNo).matches();
		}
		return false;
	}

	public static void main(String[] args) {
//		System.out.println(validMobile("13261568871"));
//		System.out.println(validCard("adasd"));
		System.out.println(validIDCard("43072319870723721Y"));
	}
}
